<?php
class SECURITY {
    var $sVipID    = "";
    var $sUserID   = 0;
    var $sUserName = '';
    var $sTrueName = '';
    var $sPetName  = '';
    var $sRole     = '';
    var $isLogIn   = false;

    var $USER_VIRT_PATH = '';
    var $USER_REAL_PATH = '';

    function SECURITY() {
        global $CFG_VIRT_FILES_ROOT,$CFG_REAL_FILES_ROOT;
        if ($this->is_login()) {
            $this->sUserID   = $_SESSION['cfg_user_id'];
            $this->sUserName = $_SESSION['cfg_user_name'];
            $this->sTrueName = '';
            $this->sPetName  = '';
            $this->sVipID    = '';
            $this->sRole     = ''; //$_SESSION['cfg_user_role'];

            $this->USER_VIRT_PATH = $CFG_VIRT_FILES_ROOT."/".$this->sUserID."/";
            $this->USER_REAL_PATH = $CFG_REAL_FILES_ROOT."/".$this->sUserID."/";
        }
    }

    function is_login() {
        if (isset($_SESSION['cfg_user_id'])   && $_SESSION['cfg_user_id'] > 0 &&
            isset($_SESSION['cfg_user_name']) && $_SESSION['cfg_user_name']!="")
        {
            $this->isLogIn = true;
            return true;
        } else {
            $this->isLogIn = false;
            return false;
        }
    }

    //check the session status, if timeout, then change the location to homepage and force to login
    function checkSession() {
        global $CFG_WWWROOT;

        //define the php file(include path info.), these files don't neet to check session
        $unCheckFile[0] = "/index2.php";

        $isUnCheck = false;
        for ($i=0; $i<count($unCheckFile); $i++) {
            if (strtolower($CFG_WWWROOT.$unCheckFile[$i]) == strtolower($_SERVER["PHP_SELF"])) $isUnCheck = true;
        }

        if (!$isUnCheck && !$this->is_login()) {
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<META http-equiv=content-type content="text/html; charset=UTF-8"/>
<TITLE>good project4u -- good project for you</TITLE>
</HEAD>
<BODY>';
            echo "<script language='javascript'>\n";
            echo "alert('您未登录或因长时间未操作，导致连接失效，请重新登陆。');\n"; //javascript 弹出窗口进行提示
            echo "window.location.href=\"/discuzwu/\";\n";
            echo "</script>\n";

echo "</body></html>";
            exit;
        } else {
            return true;
        }
    }

}
?>